"use strict";
/* Controllers */
app.controller("agentListController", ['$scope', '$location', '$rootScope', '$routeParams', 'agentListService', function ($scope, $location, $rootScope, $routeParams, agentListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};

    var errorFn = function (result) {
        alert(result);
    };

    $scope.listApiReport = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = {};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        agentListService.listApiReport(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
            pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });

        $resultTable.bootstrapTable('hideColumn', 'createTime');
        $scope.listApiReport();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('agentListService', ['ajaxService', function (ajaxService) {

    this.listApiReport = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/onduty-app-service/v1/api_report/listApiReport.do", successFunction, errorFunction);
    };
}]);

function agentOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/onduty/agent_add/id/', row.id,'" target="_blank">', "<u>修改</u>" , '</a>'
    ].join('');
}

function agentIdFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        row.agentName,"<br/>(",value,")"
    ].join('');
}


function resolvegroupNameFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/onduty/resolvegroup_add/code/', row.resolvegroupId,'" target="_blank">', "<u>",value,"</u>" , '</a>', "<br/>(",row.resolvegroupId,")"
    ].join('');
}


//function citIdsFormat(value, row, index) {
//    if (value == null) {
//        return '-';
//    }
//    var ctis = value.split(",");
//    var arr = [];
//    for (var i in ctis) {
//        var item = ctis[i];
//        var cti_cnt=item.split("|")
//        arr.push('<a href="#/star/onduty/cti_add/id/' + cti_cnt[1] + '" target="_blank">' + cti_cnt[0] + '</a>'+'<br/>（'+cti_cnt[1]+'）')
//    }
//    return arr.join('<br/>');
//}
function statusFormat(value, row, index) {
    if (value == null) {
        return '-';
    }
     switch (value) {
        case 'active':
            return '<font color="red">*</font>'+"有效";//"有效";
        case 'inactive':
            return "无效";//"无效";
        default:
            return value+"(-)";
    }
}